package com.topvision.myviewtest.mvp.demo3;

import com.topvision.myviewtest.mvp.bean.WeatherBean;
import com.topvision.myviewtest.mvp.demo3.base.AbstractMvpPresenter3;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author lucy
 * @date 2017-12-11 17:59
 * @description P层
 */

public class RequestPresenter3 extends AbstractMvpPresenter3<RequestView3> {

    private final RequestModel3 mRequestModel3;

    public RequestPresenter3() {
        mRequestModel3 = new RequestModel3();
    }

    public void clickRequest(String cityId) {
        if (getMvpView() != null) {
            getMvpView().requestLoading();
            mRequestModel3.request(cityId, new Callback<WeatherBean>() {
                @Override
                public void onResponse(Call<WeatherBean> call, Response<WeatherBean> response) {
                    if (getMvpView() != null) {
                        getMvpView().requestSuccess(response.body());
                    }
                }

                @Override
                public void onFailure(Call<WeatherBean> call, Throwable t) {
                    if (getMvpView() != null) {
                        getMvpView().requestFailure(t.toString());
                    }
                }
            });
        }
    }

    public void interrupHttp() {
        mRequestModel3.interrupHttp();
    }
}
